import axios from 'axios'

import { showFailToast } from 'vant';
const instace = axios.create({
	baseURL:'https://fc-mp-827be4c1-176f-4e1f-985a-621b4417eadf.next.bspapp.com/api'
})

//  请求 拦截器

const exemptTokenUrlList = ['/web/pub/getCategoryIndexShow','/web/pub/getBannerList','/web/pub/getIndexGoodsList'];

import { useUserStore } from '@/stores/user';

instace.interceptors.request.use(function(config){
	
let {token} = 	useUserStore()
	if(!exemptTokenUrlList.includes(config.url)){
		config.headers['uni-id-token'] = token
	}
	return config;
},function(err){
	return Promise.reject(err)
})

instace.interceptors.response.use(function(res){
	return res.data; //  
},function(err){
     if(err.status === 404){
		showFailToast('404,路径不存在')
	 }
     if(err.status === 500){
		showFailToast('500,服务器错误')
	 }
	return Promise.reject(err)
})


export default instace